package edos.prm.actor;

import java.net.URL;
import java.security.PublicKey;

/**
 * A ContactInformation of an actor encapsulates the email address, URL and
 * public key of the actor.
 */
public class ContactInformation {

	private EmailAddress emailAddress;
	private PublicKey publicKey;
	private String name;
	private URL url;
	
	/**
	 * Creates a ContactInformation object for an actor.
	 * 
	 * @param emailAddress the actor's email address
	 * @param name the String name of the actor
	 * @param url a URL for the actor
	 * @param publicKey the actor's public key
	 */
	public ContactInformation(EmailAddress emailAddress, String name, URL url,
			PublicKey publicKey) {
		super();
		this.emailAddress = emailAddress;
		this.name = name;
		this.url = url;
		this.publicKey = publicKey;
	}

	/**
	 * Creates a ContactInformation object from a name and email address
	 * 
	 * @param emailAddress an actor's email address
	 * @param name an actor's name in String format
	 */
	public ContactInformation(EmailAddress emailAddress, String name) {
		super();
		this.emailAddress = emailAddress;
		this.name = name;
		this.url = null;
		this.publicKey = null;
	}

	@Override
	public boolean equals(Object obj) {
		if ( obj instanceof ContactInformation ) {
			ContactInformation cinfo = (ContactInformation)obj;
			return ( cinfo.emailAddress.equals(this.emailAddress) &&
					cinfo.name.equalsIgnoreCase(this.name) &&
					cinfo.url.equals(this.url));
		}
		return false;
	}
	
	@Override
	public int hashCode() {
		return emailAddress.hashCode();
	}

	/**
	 * Return the email address of the contact information
	 * 
	 * @return the email address object
	 */
	public EmailAddress getEmailAddress() {
		return emailAddress;
	}

	/**
	 * Sets the email address of this object
	 *  
	 * @param emailAddress the new email address object
	 */
	public void setEmailAddress(EmailAddress emailAddress) {
		this.emailAddress = emailAddress;
	}

	/**
	 * Returns the name in this contact point
	 * 
	 * @return the contact's name in String format
	 */
	public String getName() {
		return name;
	}

	/**
	 * Sets a new new for the contact
	 * 
	 * @param name a String name for the contact
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * Returns the URL of this contact point
	 * 
	 * @return the URL in this contact information object
	 */
	public URL getUrl() {
		return url;
	}

	/**
	 * Sets a new URL for this contact point.
	 * 
	 * @param url the new URL for this contact
	 */
	public void setUrl(URL url) {
		this.url = url;
	}
	
	/**
	 * Return the public key associated with this contact
	 * 
	 * @return the PublicKey object of this contact
	 */
	public PublicKey getPublicKey() {
		return this.publicKey;
	}

	/**
	 * Make a copy of this contact information.
	 * <p>
	 * This method is useful to prevent aliasing attacks
	 * 
	 * @return a deep copy of this contact object
	 */
	public ContactInformation copy() {
		return new ContactInformation(emailAddress, name, url, publicKey);
	}
	
	
}
